const { Sequelize, Model } = require('sequelize')
const { sequelize } = require('../../core/db')

class Focus extends Model {}

Focus.init({
  id: {
    type: Sequelize.INTEGER,
    autoIncrement: true,
    primaryKey: true
  },
  linkUrl: Sequelize.STRING(100),
  imgSrc: Sequelize.STRING(300),
  orderNum: {
    type: Sequelize.INTEGER,
    defaultValue: 1
  }
}, {
  sequelize
})

// Note: using `force: true` will drop the table if it already exists
Focus.sync({ force: true }).then(() => { // 批量插入
  return Focus.bulkCreate([
    {
      linkUrl: '#',
      imgSrc: '/images/banner1.jpg',
      orderNum: 1
    },
    {
      linkUrl: '#',
      imgSrc: '/images/banner2.jpg',
      orderNum: 2
    }
  ])
})

module.exports = Focus